package com.karst.essentials.chapter10
{
	import flash.display.BitmapData;
	import flash.display.Shape;
	
	import org.papervision3d.core.geom.renderables.Particle;
	import org.papervision3d.materials.special.BitmapParticleMaterial;
	import org.papervision3d.materials.special.ParticleBitmap;

	internal class BitmapParticleMaterialShapeExample extends ParticleTemplate
	{
		public function BitmapParticleMaterialShapeExample()
		{
			super();
		}
		
		override protected function createView():void
		{
			super.createView() ;
			for( var i : int = 0 ; i < numOfPartices; i++)
			{
				var triangle : Shape = new Shape() ;
				triangle.graphics.beginFill( Math.random() * 0xFFFFFF ) ;
				triangle.graphics.moveTo( 0, 0 ) ;
				triangle.graphics.lineTo( 20, 20 ) ;
				triangle.graphics.lineTo( 40, 0 ) ;
				triangle.graphics.endFill() ;
				
				var bmpData : BitmapData = new BitmapData( 40, 20 ) ;
				bmpData.draw( triangle ) ;
				
				/**
				 * 使用动态绘制的位图作为BitmapParticleMaterial
				 */
				var material : BitmapParticleMaterial = new BitmapParticleMaterial( bmpData ) ;
				
				/**
				 * 传递一个ParticleBitmap实例给BitmapParticleMaterial构造器
				 var particleBmp : ParticleBitmap = new ParticleBitmap( triangle ) ;
				 var material : BitmapParticleMaterial = new BitmapParticleMaterial( particleBmp ) ;
				 */
				
				material.smooth = true ;
				
				var particle : Particle = new Particle( material, 1,
					randPos(), randPos(), randPos() ) ;
				particles.addParticle( particle ) ;
			}
		}
	}
}